import {ADD_PERSON_LOST, INTERGRAL_LIST, MY_INTERGRAL, INTERGRAL_TO_PRODUCT, USER_INFO, CHANGE_USER_INFO, VOLUNTEER_TIME, VOLUNTEER_LIST, STUDY_LIST, STUDY_TIME, PRODUCT_CHANGE, EXCHANGE_PRODUCT, SET_ACTIVITY, OPEN_LOCATION, END_LOCATION} from "./requestUrl.js"
import {request} from './requst.js'

import store from '../store/index.js'

// 人员走失上报
export function appendPersonLost(data) {
	return request({
		url: ADD_PERSON_LOST,
		method: 'post',
		data
	})
}

// 商品列表
export function getIntegral() {
	return request({
		url: INTERGRAL_LIST,
		method: 'post'
	})
}

// 我的积分
export function myIntegral() {
	return request({
		url: MY_INTERGRAL,
		method: 'post',
		data: {
			user_id: store.state.userInfo.user_id
		}
	})
}

// 积分兑换
export function integralToProduct(goods_id) {
	return request({
		url: INTERGRAL_TO_PRODUCT,
		method: 'post',
		data: {
			goods_id,
			user_id: store.state.userInfo.user_id
		}
	})
}

// 获取个人信息
export function getUserInfo(user_id=store.state.userInfo.user_id, isShow=true) {
	// console.log(user_id)
	return request({
		url: USER_INFO,
		method: 'post',
		data: {
			user_id
		}
	}, isShow)
}

// 修改个人信息
export function setUserInfo(data) {
	return request({
		url: CHANGE_USER_INFO,
		method: 'post',
		data: {
			...data,
			user_id: store.state.userInfo.user_id
		}
	})
}

// 	获取志愿记录
export function getVolunteerList() {
	return request({
		url: VOLUNTEER_LIST,
		method: 'post',
		data: {
			user_id: store.state.userInfo.user_id
		}
	})
}

// 获取我的志愿时数
export function getMyVolunteerTime() {
	return request({
		url: VOLUNTEER_TIME,
		method: 'post',
		data: {
			user_id: store.state.userInfo.user_id
		}
	})
}


// 	获取学习记录
export function getStudyList() {
	return request({
		url: STUDY_LIST,
		method: 'post',
		data: {
			user_id: store.state.userInfo.user_id
		}
	})
}

// 获取我的学习时数
export function getMyStudyTime() {
	return request({
		url: STUDY_TIME,
		method: 'post',
		data: {
			user_id: store.state.userInfo.user_id
		}
	})
}

// 获取商品兑换记录
export function getMyProduct() {
	return request({
		url: PRODUCT_CHANGE,
		method: 'post',
		data: {
			volunteer_id: store.state.userInfo.user_id
		}
	})
}

// 兑换商品
export function exchangeProduct(goods_id) {
	return request({
		url: EXCHANGE_PRODUCT,
		method: 'post',
		data: {
			goods_id, 
			user_id: store.state.userInfo.user_id
		}
	})
}

// 上传定位信息
export function startActivity(data) {
	console.log(data)
	return request({
		url: SET_ACTIVITY,
		method: 'post',
		data: {
			...data,
			user_id: store.state.userInfo.user_id
		}
	})
}

// 开启定位
export function startLocation() {
	return request({
		url: OPEN_LOCATION,
		method: 'post',
		data: {
			user_id: store.state.userInfo.user_id
		}
	}, false)
}

// 关闭定位
export function endLocation() {
	return request({
		url: END_LOCATION,
		method: 'post',
		data: {
			user_id: store.state.userInfo.user_id
		}
	})
}